﻿using System;
using System.Drawing;
using System.Windows.Forms;

[assembly: System.Reflection.AssemblyVersion("1.4")]

namespace MyNamespace
{
    public class MyForm : Form
    {
        private Button btnLoad;
        private PictureBox pbxPhoto;

        public MyForm()
        {
            this.Text = "Hello Form 1.4";

            //create and configure a button
            btnLoad = new Button();
            btnLoad.Text = "&load";
            btnLoad.Left = 10;
            btnLoad.Top = 10;
            btnLoad.Click += new EventHandler(this.HandleLoadClick);
            btnLoad.Anchor = AnchorStyles.Top | AnchorStyles.Left;

            //create and configure a picture box
            pbxPhoto = new PictureBox();
            pbxPhoto.BorderStyle = BorderStyle.Fixed3D;
            pbxPhoto.Width = this.Width / 2;
            pbxPhoto.Height = this.Height / 2;
            pbxPhoto.Left = (this.Width - pbxPhoto.Width) / 2;
            pbxPhoto.Top = (this.Height - pbxPhoto.Height) / 2;
            pbxPhoto.SizeMode = PictureBoxSizeMode.Zoom;
            pbxPhoto.Anchor = AnchorStyles.Top | AnchorStyles.Bottom
                               | AnchorStyles.Left | AnchorStyles.Right;
           
            //add our new controls to the form
            this.Controls.Add(btnLoad);
            this.Controls.Add(pbxPhoto);
        }

        private void HandleLoadClick(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Title = "Open Photo";
            dlg.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                pbxPhoto.Image = new Bitmap(dlg.OpenFile());
            }

            dlg.Dispose();
        }

        [System.STAThread]
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new MyForm());
        }
    }
}